package BehavioralPattern.State;


import BehavioralPattern.State.state.*;

/**
 * @Classname : Context
 * @Description : 环境角色（封装状态变化引起的功能变化）
 * @Author : chentianyu
 * @Date 2023/3/12 17:39
 */


public class Context {
    // 全部电梯状态
    public final static OpenState openState = new OpenState();
    public final static ClosedState closedState = new ClosedState();
    public final static RunningState runningState = new RunningState();
    public final static StoppedState stoppedState = new StoppedState();
    // 当前电梯状态
    private LiftState liftState;

    public LiftState getLiftState() {
        return liftState;
    }

    public void setLiftState(LiftState liftState) {
        this.liftState = liftState;
        this.liftState.setContext(this);  // 将环境信息通知到具体状态
    }

    // 电梯门开启
    public void open() {
        this.liftState.open();
    }

    // 电梯门关闭
    public void close() {
        this.liftState.close();
    }

    // 电梯运行
    public void run() {
        this.liftState.run();
    }

    // 电梯停止
    public void stop() {
        this.liftState.stop();
    }

}
